package cn.net.xyan.yypt

import cn.linkingcloud.openapi.LopClient
import cn.net.xyan.blossom.kotlin.*
import cn.net.xyan.yypt.dto.LinkingCloudResponse
import cn.net.xyan.yypt.dto.RefundOrderReq
import cn.net.xyan.yypt.dto.RefundOrderRsp
import cn.net.xyan.yypt.utils.ResourceUtils
import org.junit.Test
import java.math.BigDecimal
import java.text.SimpleDateFormat

class RefundTest{
    companion object {
        const val AppID = "LCOP20171228012536079"
        const val OpenURL = "http://openapi.linkingcloud.cn:8816/gateway"

        var charset = "utf-8"
        var sign_type = "rsa"


    }

    //@Test
    fun test1(){
        val df = SimpleDateFormat("yyyyMMddHHmmssSSS")

        val private_key = ResourceUtils.readResource("key/app_private.key")
        val public_key = ResourceUtils.readResource("key/open_public.key")

        val client = LopClient(OpenURL, AppID, private_key, charset, public_key, sign_type)

        var req = RefundOrderReq()

        req.outTradeNo = "790442"

        req.refundAmount = BigDecimal("22")
        req.tradeAmount = BigDecimal("22")

        req.outRequestNo =df.format(DateExt.now)

        req.paymentType = "alipay"

        val json = req.json

        println(json)

        val rsp = client.InvokeMethod("lc.trade.refund",json)

        println(rsp)

        val rspObj:Any? = rsp.json2obj(LinkingCloudResponse::class.parametricType(RefundOrderRsp::class.javaType))


        println(rspObj?.json)
    }
}